//设备报修
import seriveRepairs from "@/serive/seriveRepairs";

export default ({
    state: {
        repairList: [], // 保修数据
        repairListCount: 0, // 保修总条数
        scrapList: [], // 报废数据
        scrapListCount: 0, // 报废总条数
        facilityClassList: [], // 分类
        storageSiteList: [], // 地点
        Addlist: [],
    },
    getters: {
        getRepairList(state) {// 返回报修数据的列表
            return [...state.repairList]
        },
        getRepairListCount(state) {//返回总条数
            return state.repairListCount
        },
        getscrapList(state) {// 返回报修数据的列表
            return [...state.scrapList]
        },
        getscrapListCount(state) {//返回总条数
            return state.scrapListCount
        },
        getFacilityClassList(state) {
            return [...state.facilityClassList]
        },
        getStorageSiteList(state) {
            return [...state.storageSiteList]
        },
        getAddlist(state){
            return [...state.Addlist]
        }
    },
    mutations: {
        setRepairList(state, data) { // 修改保修数据
            state.repairList = data.data
            state.repairListCount = data.count
        },
        setScrapPage(state, data) { // 修改报废数据
            state.scrapList = data.data
            state.scrapListCount = data.count
        },
        setfacilityClassList(state, data) {
            state.facilityClassList = data.data
        },
        setStorageSite(state, data) {
            state.storageSiteList = data.data
        },
        getAddlist(state, data) {
            state.Addlist = data.data
        }
    },
    actions: { // 异步操作
        // 查询保修的数据
        async repairsPage({ commit }, list) {
            let res = await seriveRepairs.repairsPage(list)
            commit("setRepairList", res.data)
            console.log('res.data', res.data);
        },
        async scrapPage({ commit }, { facilityEncoding, facilityName, id, limit, page, scrapTime }) {
            console.log("in");// 获取报废数据的列表
            let res = await seriveRepairs.scrapPage(facilityEncoding, facilityName, id, limit, page, scrapTime)
            console.log("res", res.data);
            commit("setScrapPage", res.data)
        },
        async facilityClass({ commit }) { //获取设备分类
            let res = await seriveRepairs.facilityClass()
            // console.log(res.data);
            commit("setfacilityClassList", res.data)
        },
        async storageSite({ commit }) {  // 获取存放地点
            let res = await seriveRepairs.storageSite()
            console.log("存放地点",res.data); 
            commit("setStorageSite", res.data)
        },
        async scrapBathDelete({ commit }, ids) { //批量删除报废记录
            let res = await seriveRepairs.scrapBathDelete(ids)
            //   console.log(res.data);
            return res.data
        },
        async scrapDelete({ commit }, id) { //删除报废记录
            let res = await seriveRepairs.scrapDelete(id)
            console.log(res.data);
            return res.data
        },
        async repairsUpdate({ commit }, { id, maintainExpend }) { //修改数据
            console.log(id);
            let res = await seriveRepairs.repairsUpdate(id, maintainExpend)
            console.log(res.data);
            return res.data
        },
        async leasePage({ commit }, { page, limit, returnState, returnTime, facilityName }) { // 添加里面的表格数据
            let res = await seriveRepairs.leasePage(page, limit, returnState, returnTime, facilityName)
            console.log(res.data);
            commit("getAddlist", res.data)
        },
        async repairsAdd({commit},arr){ //设备保修的添加
            let res = await seriveRepairs.repairsAdd(arr)
            return res.data
        },
        async repairsBathDelete({commit},arr){ // 设备保修批量删除
            let res = await seriveRepairs.repairsBathDelete(arr)
            console.log(res.data);
            return res.data
        },
        async updateRepairs({commit},list){
            let res = await seriveRepairs.updateRepairs(list)
            console.log(res.data);
            return res.data
        },
        async scrapAdd({commit},list){
            let res =await seriveRepairs.scrapAdd(list)
            console.log(res.data);
            return res.data
        }

    },


})